package com.lzk.策略模式.使用策略模式改进代码;

/**
 * @author: zhongkui 1365693530@qq.com
 * @Date: 2024/7/15
 */
public abstract class Duck {

    //属性 策略接口
    FlyBehavior flyBehavior;

    public Duck(){
    }

    public abstract void display(); //显示鸭子信息

    public void swim(){
        System.out.println("鸭子游泳~~~");
    }

    public void quack(){
        System.out.println("鸭子嘎嘎叫~~~");
    }
    public void fly(){
        //改进
        if (flyBehavior != null){
            flyBehavior.fly();
        }
    }


    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }
}
